﻿/**
* LoadBinaryDataHandler.cs
* 
**/
using System;
using System.Web;
using System.Web.SessionState;

using Yawf.Core;
using Yawf.Core.Logs;

namespace Yawf.Web.HttpHandlers {
	/// <summary>
	/// A MVC Http Handler, here is we all good stuff happens
	/// 
	/// </summary>
	public class LoadBinaryDataHandler : IHttpHandler, IRequiresSessionState {
		LoadBinaryDataController binaryController = null;
		/// <summary>
		/// Is Reusable Property, always returns true, cause we can
		/// handle being in a thread pool
		/// </summary>
		public bool IsReusable {get{return true;}}

		/// <summary>
		/// Gets the LoadBinaryController that really do all the http handling
		/// </summary>
		/// <param name="context">HttpContext to use</param>
		/// <returns>A LoadBinaryDataController object</returns>
		public LoadBinaryDataController GetLoadBinaryDataController(HttpContext context) {
			Initializer initializer;

			if (binaryController != null) {
				return binaryController;
			}

			// Get VCG Framework initializer
			initializer = Initializer.Instance;
			if (initializer != null && initializer.ContainsObject("binaryDataController")) {
				binaryController = (LoadBinaryDataController)initializer.GetObject("binaryDataController");
			} else {
				Log.FatalMessage(this.GetType(), "Cannot find binaryDataController, you must define the binaryDataController objet in Spring.Net Configuration");
			}

			return binaryController;
		}								// GetLoadBinaryDataController

		/// <summary>
		/// A http handler that really uses a LoadBinaryDataController object to 
		/// handle all http stuff, this is just a wrapper class cause
		/// the LoadBinaryDataController is created via Spring.NET and injected with 
		/// all classes that really do the stuff
		/// </summary>
		/// <param name="context">HttpContext to use</param>
		public void ProcessRequest(HttpContext context) {
			GetLoadBinaryDataController(context).ProcessRequest(context);
		}												// ProcessRequest

	}
}
